﻿@model Matrix.MaKaYunShang.Model.McCashWithdrawApplication
@{
    ViewBag.Title = "添加提现记录";
    ViewBag.PathToBtn = "/Withdrawals/List";
    ViewBag.TextBtn = "返回至列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                添加提现记录
            </div>
            <div class="panel-body">
                <div class="row">
                    @using (Html.BeginForm("Create", "Withdrawals", FormMethod.Post, new {id = "frmCreate", enctype = "multipart/form-data"}))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)

                        <div class="col-lg-12">
                            <fieldset>
                                <div class="form-group col-md-6">
                                    <label>选择店铺</label>
                                    <div class="input-group">
                                        @Html.HiddenFor(model => model.ShopId)
                                        <input type="text" class=" form-control" data-target="#ShopModel" data-toggle="modal" name="ShopName" id="ShopName" placeholder="选择店铺" readonly="readonly" >
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>提现金额</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.CashValue, new {@class = "form-control", placeholder = "提现金额", maxlength = 10})
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>备注</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.Remark, new { @class = "form-control ", placeholder = "备注" })
                                        <span class="input-group-addon red"></span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>支付时间</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.PayTime, new { @class = "form-control form_datetime", placeholder = "支付时间", @readonly = "readonly" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                   
                                <div class="col-md-12">
                                    <button id="btnSave" type="button" class="btn btn-primary">保存</button>
                                    <button id="btnReset" type="reset" class="btn btn-outline btn-primary">清空设置</button>
                                </div>
                            </fieldset>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="ShopModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 600px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查询店铺</h4>
            </div>
            <div class="modal-body">
                <div style="margin-bottom: 5px;">
                    <input type="text" class="form-control" placeholder="店铺名称" value="成都" style="width: 359px; display: inline-block" id="ShopNameKeyWords"/>
                    <a class="btn btn-primary" onclick="searchShopList();">查询</a>
                </div>
                <div class="table-responsive table-bordered" style="max-height: 250px;">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>店铺名称</th>
                                <th>地址</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                        </thead>
                        <tbody id="ShopNameData"></tbody>
                    </table>
                    <input type="hidden" id="hidOrderId" />
                </div>
            </div>
        </div>
    </div>
</div>
@section javascript{
    <script type="text/javascript">
        $(function () {
        
            $("#frmCreate").validate({
                rules: {
                    ShopName: { required: true },
                    CashValue: { required: true, digits: true },
                    PayTime: { required: true }
                },
                messages: {
                    ShopName: { required: "请选择店铺" },
                    CashValue: { required: "请填写提现金额" },
                    PayTime: { required: "请填写支付时间" }
                }
            });

            searchShopList();
            $("#btnSave").click(function () {
             
                if ($("#frmCreate").valid()) {
                    var cashValue = $("#CashValue").val();
                    if (!isNaN(cashValue)) {

                    } else {
                        return alertify.alert('请填写正确的金额');
                    }
                    if (cashValue < 1) {
                        return alertify.alert('提现金额必须大于0');
                    }
                    var r = confirm("确认要添加吗?");
                    if (r == false) {
                        return false;
                    }
                    $.ajax({
                        type: 'post',
                        url: '@Url.Action("Create")',
                        data: $("#frmCreate").serialize(),
                        success: function (data) {
                            if (data.Status) {
                                alertify.success("保存成功");
                                setTimeout(function () {
                                    window.location.href = "/Withdrawals/List";
                                }, 500);
                            } else {
                                alertify.error(data.Message);
                            }
                        },
                        error: function () {
                            alertify.error("保存失败，请重试！");
                        }
                    });
                }
            });
        });
        function searchShopList() {
            $("#ShopNameData").html("");
            $.post("@Url.Action("GetShopList")", "&keyWords=" + encodeURIComponent($("#ShopNameKeyWords").val()), function (data) {
                if (data.Status) {
                    for (var i = 0; i < data.Data.length; i++) {
                        $("#ShopNameData").append("<tr><td id='shopName" + data.Data[i].Id + "'>" + data.Data[i].Name + "</td><td>" + data.Data[i].Address + "</td><td align='center'><a class='btn btn-info' onclick='selectCommdityId(" + data.Data[i].Id + ");'>选择</a></td></tr>");
                    }
                } else {
                    alertify.alert(data.Message);
                }
            });
        }


        function selectCommdityId(shopId) {
            $("#ShopName").val($("#shopName" + shopId).html());
            $("#ShopId").val(shopId);
            $("#ShopModel").modal("hide");
        }
    </script>
}